﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace CreatePGSQLDataScript
{
    public partial class QueryApfield : Form
    {
        public QueryApfield()
        {
            InitializeComponent();
        }
        DataAccess.SqlProvider db;
        
        private void QueryApfield_Load(object sender, EventArgs e)
        {
            db = new DataAccess.SqlProvider(OisLibrary.DB.Connection);
            gridDllCondition.AutoGenerateColumns = false;
        }

        private void btnQuery_Click(object sender, EventArgs e)
        {

            //DDLCondition
            string sqlText = string.Format(@"
select COUNT(1) as times ,DDLConditions as value
from apfield where apfield.fid='{0}' 
and DDLConditions!=''  
group by DDLConditions 
order by COUNT(1) desc", txtFeild.Text.Trim());

            DataTable dt= db.GetDataTable(sqlText);
            gridDllCondition.DataSource = dt;


            //LeftJoin
            sqlText = string.Format(@"
select COUNT(1) as times ,JoinConditions as value
from apfield where apfield.fid='{0}' 
and JoinConditions!=''  
group by JoinConditions 
order by COUNT(1) desc", txtFeild.Text.Trim());

            DataTable dt2 = db.GetDataTable(sqlText);
            gridLeftJoin.DataSource = dt2;


        }

        private void gridDllCondition_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            DataGridViewRow dr = gridDllCondition.CurrentRow;
            string value = dr.Cells[1].Value.ToString();
            rtxtDetail.Text = value;
        }

        private void gridLeftJoin_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            DataGridViewRow dr = gridLeftJoin.CurrentRow;
            string value = dr.Cells[1].Value.ToString();
            rtxtDetail.Text = value;
        }


    }
}
